package com.cloud.shopping.listener;

import com.cloud.shopping.goods.feign.SkuFeign;
import com.cloud.shopping.goods.model.AdItems;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

import javax.annotation.Resource;

/**
 * @author John.zhang
 * @version Id: AdItemsHandler, v 1.0 2020/12/30 16:46 ZhiYong Exp $
 */

@Component
@CanalTable(value = "ad_items")
public class AdItemsHandler implements EntryHandler<AdItems> {

    @Resource
    private SkuFeign skuFeign;

    /**
     * 数据库增加数据，执行该方法
     *
     * @param adItems adItems
     */
    @Override
    public void insert(AdItems adItems) {
        skuFeign.updateTypeItems(adItems.getType());
    }

    /**
     * 数据库修改数据，执行该方法
     *
     * @param before before
     * @param after  after
     */
    @Override
    public void update(AdItems before, AdItems after) {
        if (before.getType() != null && before.getType().intValue() != after.getType().intValue()) {
            skuFeign.updateTypeItems(before.getType());
        }
        System.out.println(skuFeign.updateTypeItems(after.getType()));
    }

    /**
     * 数据库删除数据，执行该方法
     *
     * @param adItems adItems
     */
    @Override
    public void delete(AdItems adItems) {
        skuFeign.delTypeItems(adItems.getType());
    }
}
